from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.

from curd_demo.models import CrudDemoModel
from curd_demo.serializers import CrudDemoModelCreateUpdateSerializer, CrudDemoModelSerializer
from dvadmin.utils.viewset import CustomModelViewSet
from dvadmin.utils.permission import CustomPermission

class OpenapiPermission(CustomPermission):
    def has_permission(self, request, view):
        return True
    def has_object_permission(self, request, view, obj):
        return True

class CrudDemoModelViewSet(CustomModelViewSet):
    '''
        list: 查询
        create:新增
        update:修改
        retrieve:单例
        destory:删除
    '''
    permission_classes = [OpenapiPermission,]

    queryset = CrudDemoModel.objects.all()
    serializer_class = CrudDemoModelSerializer
    create_serializer_class = CrudDemoModelCreateUpdateSerializer
    update_serializer_class = CrudDemoModelCreateUpdateSerializer
    filter_fields = ['goods', 'goods_price']
    search_fields = ['goods']
    extra_filter_backends = []



def test(request):
    print('test:::')
    return  HttpResponse('test ,running......')